package cn.audit.repository.log;

import cn.audit.bean.dto.UserCorrelation;
import cn.audit.bean.pojo.WorkLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @Author: 李忆枫
 * @Date: 2019/5/23 17:19
 */
public interface WorkLogRepository extends JpaRepository<WorkLog, Long>, JpaSpecificationExecutor<WorkLog> {


    @Query(value = "select new cn.audit.bean.dto.UserCorrelation(u,p,w) " +
            "from User u,Project1 p, WorkLog w " +
            "where w.projectId = p.id and w.userId = u.id " +
            "and (?1=null or p.name like %?1%) " +
            "and (?2=null or w.submissiondate like %?2%)")
    List<UserCorrelation> findWorkLog(String name, String submissiondate);


    /**
     * 在 @Query 注解中编写 JPQL 语句，
     * 但必须使用 @Modifying 进行修饰.
     * 以通知 SpringData， 这是一个 UPDATE 或 DELETE 操作
     *
     * @param ids
     */
    @Modifying(clearAutomatically = true)
    @Query(value = "DELETE FROM WorkLog w  WHERE w.id IN ?1")
    void batchDelete(List<Long> ids);


}
